package com.mass.waybill.order.controller;

import com.mass.core.sys.dict.model.SysDictVal;
import com.mass.core.sys.dict.service.SysDictValService;
import com.mass.core.sys.user.model.SysUser;
import com.mass.core.utils.AjaxResponse;
import com.mass.core.utils.DateUtils;
import com.mass.core.utils.ExcelUtil;
import com.mass.core.utils.NumberUtils;
import com.mass.waybill.order.model.WbShippingOrder;
import com.mass.waybill.order.service.WbShippingOrderService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Author: ZSX
 * @Description: 订单controller
 */
@RestController
@RequestMapping("/wb/shipping/order")
public class WbShippingOrderController {

    @Autowired
    private WbShippingOrderService wbShippingOrderService;

    @Autowired
    private SysDictValService sysDictValService;

    /**
     * 增加
     *
     * @param wbShippingOrder
     * @return
     */
    @ApiOperation(value = "添加一个实例", notes = "添加wbShippingOrder")
    @PostMapping("/insert")
    public AjaxResponse insert(WbShippingOrder wbShippingOrder, HttpSession session) {
        Object object = session.getAttribute("sysUser");
        if (!ObjectUtils.isEmpty(object)) {
            SysUser sysUser = (SysUser) object;
            wbShippingOrder.setSalesman(sysUser.getName());
        } else {
            return AjaxResponse.success("未登录！");
        }
        int number = wbShippingOrderService.insert(wbShippingOrder);
        return AjaxResponse.success(number);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "添加一个实例", notes = "删除wbShippingOrder")
    @ApiImplicitParam(name = "id", value = "id", paramType = "query", dataType = "Long", required = true)
    @PostMapping("/delete")
    public AjaxResponse delete(@NotNull(message = "id不能为空") Long id) {
        int number = wbShippingOrderService.delete(id);
        return AjaxResponse.success(number);
    }

    /**
     * 修改订单
     *
     * @param wbShippingOrder
     * @return
     */
    @ApiOperation(value = "修改", notes = "修改wbShippingOrder")
    @PostMapping("/update")
    public AjaxResponse update(WbShippingOrder wbShippingOrder, HttpSession session) {
        Object object = session.getAttribute("sysUser");
        if (!ObjectUtils.isEmpty(object)) {
            SysUser sysUser = (SysUser) object;
            if (!ObjectUtils.isEmpty(wbShippingOrder.getAudit())) {
                wbShippingOrder.setModifier(sysUser.getName());
                wbShippingOrder.setModifyTime(DateUtils.getDate("yyyy年MM月dd日 HH:mm"));
            }
            if (ObjectUtils.isEmpty(wbShippingOrder.getIsInvoice())) {
                wbShippingOrder.setIsInvoice(0);
            }
            if (ObjectUtils.isEmpty(wbShippingOrder.getWhetherSelfTransport())) {
                wbShippingOrder.setWhetherSelfTransport(0);
            }
            if (ObjectUtils.isEmpty(wbShippingOrder.getStandby())) {
                wbShippingOrder.setStandby("0");
            }
            if (ObjectUtils.isEmpty(wbShippingOrder.getDriver())) {
                wbShippingOrder.setDriver("");
            }
            if (ObjectUtils.isEmpty(wbShippingOrder.getLicensePlate())) {
                wbShippingOrder.setLicensePlate("");
            }
        } else {
            return AjaxResponse.success("未登录！");
        }
        int number = wbShippingOrderService.update(wbShippingOrder);
        return AjaxResponse.success(number);
    }

    /**
     * 确认订单
     *
     * @param wbShippingOrder
     * @return
     */
    @PostMapping("/makeOrder")
    public AjaxResponse makeOrder(WbShippingOrder wbShippingOrder, HttpSession session) {
        Object object = session.getAttribute("sysUser");
        if (!ObjectUtils.isEmpty(object)) {
            SysUser sysUser = (SysUser) object;
            wbShippingOrder.setConfirmPeople(sysUser.getName());
            wbShippingOrder.setConfirmTime(DateUtils.getDate("yyyy年MM月dd日 HH:mm"));
            if (ObjectUtils.isEmpty(wbShippingOrder.getIsInvoice())) {
                wbShippingOrder.setIsInvoice(0);
            }
            if (ObjectUtils.isEmpty(wbShippingOrder.getWhetherSelfTransport())) {
                wbShippingOrder.setWhetherSelfTransport(0);
            }
            if (ObjectUtils.isEmpty(wbShippingOrder.getStandby())) {
                wbShippingOrder.setStandby("0");
            }
        } else {
            return AjaxResponse.success("未登录！");
        }
        int number = wbShippingOrderService.update(wbShippingOrder);
        return AjaxResponse.success(number);
    }

    /**
     * 通过id查找
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据ID查找实例", notes = "通过id查找详情")
    @ApiImplicitParam(name = "id", value = "id", paramType = "query", dataType = "Long", required = true)
    @PostMapping("/selectById")
    public AjaxResponse selectById(@NotNull(message = "id不能为空") Long id) {
        WbShippingOrder wbShippingOrder = wbShippingOrderService.selectById(id);
        return AjaxResponse.success(wbShippingOrder);
    }

    /**
     * 修改 不包含费用明细
     *
     * @param wbShippingOrder
     * @return
     */
    @PostMapping("/updateWbShippingOrder")
    public AjaxResponse updateWbShippingOrder(WbShippingOrder wbShippingOrder) {
        return AjaxResponse.success(wbShippingOrderService.updateWbShippingOrder(wbShippingOrder));
    }

    /**
     * 分页条件查找
     *
     * @param input 输入对象
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(value = "列表查询", paramType = "query", required = false, dataType = "WbShippingOrder"),
            @ApiImplicitParam(name = "page", value = "当前页", paramType = "query", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "limit", value = "查询行", paramType = "query", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/selectPage")
    public AjaxResponse selectPage(WbShippingOrder wbShippingOrder, Integer page, Integer limit) {
        return wbShippingOrderService.selectPage(wbShippingOrder, page, limit);
    }

    /**
     * 导出费用统计表
     *
     * @param wbShippingOrder
     * @param response
     */
    @RequestMapping("/export")
    public void export(WbShippingOrder wbShippingOrder, HttpServletResponse response) {
        AjaxResponse ajaxResponse = wbShippingOrderService.selectPage(wbShippingOrder, 1, 99999999);
        Object object = ajaxResponse.getData();
        //查询所有数据字典
        List<SysDictVal> sysDictValList = sysDictValService.getByTypeCode(null,null,null, null, null, null);
        //数据字典 Map  key  字典编码  value  字典值
        Map<String, String> dictMap = new HashMap<String, String>();
        for (SysDictVal sysDictVal : sysDictValList) {
            dictMap.put(sysDictVal.getValCode(), sysDictVal.getValName());
        }
        //查询应收信息
        List<WbShippingOrder> wbShippingOrderList = new ArrayList<>();
        if (!ObjectUtils.isEmpty(object)) {
            wbShippingOrderList = (List<WbShippingOrder>) object;
        }
        //表头
        String[] titles = {"序号", "订单编号", "业务员", "下单日期", "业务类型", "品名", "箱型", "箱号", "发货单位", "装货地点", "发出", "到站", "收货人", "结算人", "自运输", "司机", "车牌", "需开票", "状态"};
        if (!ObjectUtils.isEmpty(wbShippingOrder) && !ObjectUtils.isEmpty(wbShippingOrder.getStandby2()) && "2".equals(wbShippingOrder.getStandby2().trim())) {
            titles = new String[]{"序号", "订单编号", "业务员", "下单日期", "业务类型", "品名", "箱型", "箱号", "发货单位", "装货地点", "发出港", "到港", "收货人", "结算人", "自运输", "司机", "车牌", "需开票", "状态"};
        }
        //文件名
        String fileName = "货运订单表";
        ServletOutputStream out = null;
        try {
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet();
            int colNum = titles.length;
            int rowNO = 0;
            ExcelUtil.createExcelRow(workbook, sheet, rowNO, -1, colNum, "货运订单表");
            rowNO = rowNO + 1;
            ExcelUtil.createExcelRow(workbook, sheet, rowNO, 200, colNum, "制 表 日 期: " + (new SimpleDateFormat("yyyy-MM-dd")).format(new Date()), 180, "normal", "right");
            ++rowNO;
            ExcelUtil.createColumnHeader(workbook, sheet, rowNO, 300, titles);
            ++rowNO;
            String[][] strings = new String[wbShippingOrderList.size()][titles.length];
            //应付金额   实付金额
            Double accountsReceivableAmount = 0.00, sterilisationAmount = 0.00;
            for (int i = 0; i < wbShippingOrderList.size(); ++i) {
                WbShippingOrder order = wbShippingOrderList.get(i);
                strings[i][0] = (i + 1) + "";               //序号
                strings[i][1] = order.getOrderCode();        //订单编号
                strings[i][2] = order.getSalesman();        //业务员
                strings[i][3] = order.getOrderDate();       //下单日期
                strings[i][4] = !ObjectUtils.isEmpty(dictMap.get(order.getBusinessTypes())) ? dictMap.get(order.getBusinessTypes()) : "—";               //业务类型
                strings[i][5] = !ObjectUtils.isEmpty(dictMap.get(order.getOfTheGoods())) ? dictMap.get(order.getOfTheGoods()) : "—";               //品名
                strings[i][6] = !ObjectUtils.isEmpty(dictMap.get(order.getaBox())) ? dictMap.get(order.getaBox()) : "—"; //箱型
                strings[i][7] = !ObjectUtils.isEmpty(order.getCartonNo()) ? order.getCartonNo() : "";               //箱号
                strings[i][8] = !ObjectUtils.isEmpty(dictMap.get(order.getDeliveryUnit())) ? dictMap.get(order.getDeliveryUnit()) : "—";//发货单位
                strings[i][9] = !ObjectUtils.isEmpty(dictMap.get(order.getStandby1())) ? dictMap.get(order.getStandby1()) : "—";//装货地点
                strings[i][10] = !ObjectUtils.isEmpty(dictMap.get(order.getaStation())) ? dictMap.get(order.getaStation()) : "—";///发出
                strings[i][11] = !ObjectUtils.isEmpty(dictMap.get(order.getArriveStation())) ? dictMap.get(order.getArriveStation()) : "—"; //到站
                strings[i][12] = !ObjectUtils.isEmpty(dictMap.get(order.getReceivingUnit())) ? dictMap.get(order.getReceivingUnit()) : "—";//收货人
                strings[i][13] = !ObjectUtils.isEmpty(dictMap.get(order.getSettlementPeople())) ? dictMap.get(order.getSettlementPeople()) : "—";//结算人
                if (!ObjectUtils.isEmpty(order.getWhetherSelfTransport()) && order.getWhetherSelfTransport() == 1) {
                    strings[i][14] = "是";  //自运输
                } else {
                    strings[i][14] = "否";  //自运输
                }
                strings[i][15] = !ObjectUtils.isEmpty(dictMap.get(order.getDriver())) ? dictMap.get(order.getDriver()) : "—";      //司机
                strings[i][16] = !ObjectUtils.isEmpty(dictMap.get(order.getLicensePlate())) ? dictMap.get(order.getLicensePlate()) : "—";      //车牌
                if (!ObjectUtils.isEmpty(order.getIsInvoice()) && order.getIsInvoice() == 1) {
                    strings[i][17] = "是";  //需开票
                } else {
                    strings[i][17] = "否";  //需开票
                }
                //状态
                if (!ObjectUtils.isEmpty(order.getStates())) {
                    if (order.getStates() == -1) {
                        strings[i][18] = "暂存";  //状态
                    } else if (order.getStates() == 0) {
                        strings[i][18] = "已下单";  //状态
                    } else if (order.getStates() == 1) {
                        strings[i][18] = "已发运";  //状态
                    } else if (order.getStates() == 2) {
                        strings[i][18] = "待收款";  //状态
                    } else if (order.getStates() == 3) {
                        strings[i][18] = "已收款";  //状态
                    }
                } else {
                    strings[i][18] = "—";  //状态
                }
            }
            sheet = ExcelUtil.createColumnData(workbook, sheet, rowNO, strings, wbShippingOrderList.size() + 3);
            ExcelUtil.createSummaryRow(workbook, sheet, colNum, "行数合计：" + strings.length, 180, "normal", "right");

            fileName = fileName + (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date());
            out = response.getOutputStream();
            response.setContentType("application/ms-excel;charset=UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1") + ".xls");
            workbook.write(out);
        } catch (
                Exception var35) {
            var35.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException var34) {
                var34.printStackTrace();
            }

        }
    }

    /**
     * 运单导出
     */
    @RequestMapping("/wayBillExport")
    public void wayBillExport(WbShippingOrder wbShippingOrder, Integer page, Integer limit, HttpServletResponse response) {
        AjaxResponse ajaxResponse = null;
        if( !ObjectUtils.isEmpty(page)){
            ajaxResponse = wbShippingOrderService.selectPage(wbShippingOrder, page, limit);
        }else{
            ajaxResponse = wbShippingOrderService.selectPage(wbShippingOrder, 1, 99999999);
        }
        Object object = ajaxResponse.getData();
        //查询所有数据字典
        List<SysDictVal> sysDictValList = sysDictValService.getByTypeCode(null,null,null, null, null, null);
        //数据字典 Map  key  字典编码  value  字典值
        Map<String, String> dictMap = new HashMap<String, String>();
        for (SysDictVal sysDictVal : sysDictValList) {
            dictMap.put(sysDictVal.getValCode(), sysDictVal.getValName());
        }
        //查询应收信息
        List<WbShippingOrder> wbShippingOrderList = new ArrayList<>();
        if (!ObjectUtils.isEmpty(object)) {
            wbShippingOrderList = (List<WbShippingOrder>) object;
        }
        //表头
        String[] titles = {"序号", "订单编号", "业务员", "日期", "业务类型", "品名", "箱型", "箱号", "发货单位", "装货地点", "发出站", "到站", "收货人", "结算人", "已开发票", "货票号","计费重量", "应收金额", "费用总额", "状态"};
        if (!ObjectUtils.isEmpty(wbShippingOrder) && !ObjectUtils.isEmpty(wbShippingOrder.getStandby2()) && "2".equals(wbShippingOrder.getStandby2().trim())) {
            titles = new String[]{"序号", "订单编号", "业务员", "日期", "业务类型", "品名", "箱型", "箱号", "发货单位", "装货地点", "发出港", "到港", "收货人", "结算人", "已开发票", "货票号","计费重量", "应收金额", "费用总额", "状态"};
        }else if(!ObjectUtils.isEmpty(wbShippingOrder) && !ObjectUtils.isEmpty(wbShippingOrder.getStandby2()) && "1".equals(wbShippingOrder.getStandby2().trim())){
            //货物运单 铁    多一个字段    到站承运
            titles = new String[]{"序号", "订单编号", "业务员", "日期", "业务类型", "品名", "箱型", "箱号", "发货单位", "装货地点", "发出站", "到站","到站承运", "收货人", "结算人", "已开发票", "货票号","计费重量", "应收金额", "费用总额", "状态"};
        }
        //文件名
        String fileName = "货物运单表";
        ServletOutputStream out = null;
        try {
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet();
            int colNum = titles.length;
            int rowNO = 0;
            ExcelUtil.createExcelRow(workbook, sheet, rowNO, -1, colNum, "货物运单表");
            rowNO = rowNO + 1;
            ExcelUtil.createExcelRow(workbook, sheet, rowNO, 200, colNum, "制 表 日 期: " + (new SimpleDateFormat("yyyy-MM-dd")).format(new Date()), 180, "normal", "right");
            ++rowNO;
            ExcelUtil.createColumnHeader(workbook, sheet, rowNO, 300, titles);
            ++rowNO;
            String[][] strings = new String[wbShippingOrderList.size()][titles.length];
            //应收金额   费用总额
            Double accountsReceivableAmount = 0.00, sterilisationAmount = 0.00;
            for (int i = 0; i < wbShippingOrderList.size(); ++i) {
                WbShippingOrder order = wbShippingOrderList.get(i);
                strings[i][0] = (i + 1) + "";               //序号
                strings[i][1] = order.getOrderCode();        //订单编号
                strings[i][2] = order.getSalesman();        //业务员
                strings[i][3] = order.getOrderDate();       //下单日期
                strings[i][4] = !ObjectUtils.isEmpty(dictMap.get(order.getBusinessTypes())) ? dictMap.get(order.getBusinessTypes()) : "—";               //业务类型
                strings[i][5] = !ObjectUtils.isEmpty(dictMap.get(order.getOfTheGoods())) ? dictMap.get(order.getOfTheGoods()) : "—";               //品名
                strings[i][6] = !ObjectUtils.isEmpty(dictMap.get(order.getaBox())) ? dictMap.get(order.getaBox()) : "—"; //箱型
                strings[i][7] = !ObjectUtils.isEmpty(order.getCartonNo()) ? order.getCartonNo() : "";               //箱号
                strings[i][8] = !ObjectUtils.isEmpty(dictMap.get(order.getDeliveryUnit())) ? dictMap.get(order.getDeliveryUnit()) : "—";//发货单位
                strings[i][9] = !ObjectUtils.isEmpty(dictMap.get(order.getStandby1())) ? dictMap.get(order.getStandby1()) : "—";//装货地点
                strings[i][10] = !ObjectUtils.isEmpty(dictMap.get(order.getaStation())) ? dictMap.get(order.getaStation()) : "—";///发出
                strings[i][11] = !ObjectUtils.isEmpty(dictMap.get(order.getArriveStation())) ? dictMap.get(order.getArriveStation()) : "—"; //到站
                if(!ObjectUtils.isEmpty(wbShippingOrder) && !ObjectUtils.isEmpty(wbShippingOrder.getStandby2()) && "1".equals(wbShippingOrder.getStandby2().trim())){
                    strings[i][12] = !ObjectUtils.isEmpty(dictMap.get(order.getStandby3())) ? dictMap.get(order.getStandby3()) : "—";//到站承运

                    strings[i][13] = !ObjectUtils.isEmpty(dictMap.get(order.getReceivingUnit())) ? dictMap.get(order.getReceivingUnit()) : "—";//收货人
                    strings[i][14] = !ObjectUtils.isEmpty(dictMap.get(order.getSettlementPeople())) ? dictMap.get(order.getSettlementPeople()) : "—";//结算人

                    if (!ObjectUtils.isEmpty(order.getStandby()) && "1".equals(order.getStandby())) {
                        strings[i][15] = "是";  //已开发票
                    } else {
                        strings[i][15] = "否";  //已开发票chargeableWeight
                    }
                    strings[i][16] = !ObjectUtils.isEmpty(order.getGoodsWere()) ? order.getGoodsWere() : "—";      //货票号
                    strings[i][17] = !ObjectUtils.isEmpty(order.getChargeableWeight()) ? order.getChargeableWeight() : "—";  //计费重量

                    if(!ObjectUtils.isEmpty(order.getAccountsReceivableAmount())){
                        strings[i][18] = String.format("%.2f", Double.parseDouble(order.getAccountsReceivableAmount().trim())); //应收金额
                        accountsReceivableAmount = NumberUtils.add(accountsReceivableAmount, Double.parseDouble(order.getAccountsReceivableAmount().trim()));
                    }else{
                        strings[i][18] = "—"; //应收金额
                    }
                    if(!ObjectUtils.isEmpty(order.getTotalCosts())){
                        strings[i][19] = String.format("%.2f", Double.parseDouble(order.getTotalCosts().trim())); //费用总额
                        sterilisationAmount = NumberUtils.add(sterilisationAmount, Double.parseDouble(order.getTotalCosts().trim()));
                    }else{
                        strings[i][19] = "—"; //费用总额totalCosts
                    }
                    //状态
                    if (!ObjectUtils.isEmpty(order.getStates()) && order.getStates() == -1) {
                        if (order.getStates() == -1) {
                            strings[i][20] = "暂存";  //状态
                        } else if (order.getStates() == 0) {
                            strings[i][20] = "已下单";  //状态
                        } else if (order.getStates() == 1) {
                            strings[i][20] = "已发运";  //状态
                        } else if (order.getStates() == 2) {
                            strings[i][20] = "待收款";  //状态
                        } else if (order.getStates() == 3) {
                            strings[i][19] = "已收款";  //状态
                        }
                    } else {
                        strings[i][20] = "—";  //状态
                    }
                }else{
                    strings[i][12] = !ObjectUtils.isEmpty(dictMap.get(order.getReceivingUnit())) ? dictMap.get(order.getReceivingUnit()) : "—";//收货人
                    strings[i][13] = !ObjectUtils.isEmpty(dictMap.get(order.getSettlementPeople())) ? dictMap.get(order.getSettlementPeople()) : "—";//结算人

                    if (!ObjectUtils.isEmpty(order.getStandby()) && "1".equals(order.getStandby())) {
                        strings[i][14] = "是";  //已开发票
                    } else {
                        strings[i][14] = "否";  //已开发票chargeableWeight
                    }
                    strings[i][15] = !ObjectUtils.isEmpty(order.getGoodsWere()) ? order.getGoodsWere() : "—";      //货票号
                    strings[i][16] = !ObjectUtils.isEmpty(order.getChargeableWeight()) ? order.getChargeableWeight() : "—";  //计费重量

                    if(!ObjectUtils.isEmpty(order.getAccountsReceivableAmount())){
                        strings[i][17] = String.format("%.2f", Double.parseDouble(order.getAccountsReceivableAmount().trim())); //应收金额
                        accountsReceivableAmount = NumberUtils.add(accountsReceivableAmount, Double.parseDouble(order.getAccountsReceivableAmount().trim()));
                    }else{
                        strings[i][17] = "—"; //应收金额
                    }
                    if(!ObjectUtils.isEmpty(order.getTotalCosts())){
                        strings[i][18] = String.format("%.2f", Double.parseDouble(order.getTotalCosts().trim())); //费用总额
                        sterilisationAmount = NumberUtils.add(sterilisationAmount, Double.parseDouble(order.getTotalCosts().trim()));
                    }else{
                        strings[i][18] = "—"; //费用总额totalCosts
                    }
                    //状态
                    if (!ObjectUtils.isEmpty(order.getStates())) {
                        if (order.getStates() == -1) {
                            strings[i][19] = "暂存";  //状态
                        } else if (order.getStates() == 0) {
                            strings[i][19] = "已下单";  //状态
                        } else if (order.getStates() == 1) {
                            strings[i][19] = "已发运";  //状态
                        } else if (order.getStates() == 2) {
                            strings[i][19] = "待收款";  //状态
                        } else if (order.getStates() == 3) {
                            strings[i][19] = "已收款";  //状态
                        }
                    } else {
                        strings[i][19] = "—";  //状态
                    }
                }
            }
            if(!ObjectUtils.isEmpty(wbShippingOrder) && !ObjectUtils.isEmpty(wbShippingOrder.getStandby2()) && "1".equals(wbShippingOrder.getStandby2().trim())) {
                sheet = ExcelUtil.createColumnData(workbook, sheet, rowNO, strings, wbShippingOrderList.size() + 3);
                //最后一行
                HSSFRow lastRow = sheet.createRow((short) (sheet.getLastRowNum() + 1));
                lastRow.createCell(1).setCellValue(new HSSFRichTextString("合计："));
                lastRow.createCell(18).setCellValue(new HSSFRichTextString(String.format("%.2f", accountsReceivableAmount)));
                lastRow.createCell(19).setCellValue(new HSSFRichTextString(String.format("%.2f", sterilisationAmount)));
            }else{
                sheet = ExcelUtil.createColumnData(workbook, sheet, rowNO, strings, wbShippingOrderList.size() + 3);
                //最后一行
                HSSFRow lastRow = sheet.createRow((short) (sheet.getLastRowNum() + 1));
                lastRow.createCell(1).setCellValue(new HSSFRichTextString("合计："));
                lastRow.createCell(17).setCellValue(new HSSFRichTextString(String.format("%.2f", accountsReceivableAmount)));
                lastRow.createCell(18).setCellValue(new HSSFRichTextString(String.format("%.2f", sterilisationAmount)));
            }
           // ExcelUtil.createSummaryRow(workbook, sheet, colNum, "行数合计：" + strings.length, 180, "normal", "right");

            fileName = fileName + (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date());
            out = response.getOutputStream();
            response.setContentType("application/ms-excel;charset=UTF-8");
            response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1") + ".xls");
            workbook.write(out);
        } catch (
                Exception var35) {
            var35.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException var34) {
                var34.printStackTrace();
            }

        }
    }
}
